home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 322 / compsrc4 / write.c < prev   
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.3 KB  |  75 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  * $Header: write.c,v 1.2 88/02/03 22:56:45 m68k Exp $
  6.  *
  7.  * $Log:    write.c,v $
  8.  *
  9.  * 1.3    jrd
  10.  *
  11.  * Revision 1.2  88/02/03  22:56:45  m68k
  12.  * Added unix like tty driver stuff
  13.  * 
  14.  * Revision 1.1  88/01/29  17:32:06  m68k
  15.  * Initial revision
  16.  * 
  17.  */
  18. /* #include    <gembios.h>    ?? */
  19. #include    <osbind.h>
  20. #include    <ioctl.h>
  21. #include    "tchars.h"
  22.  
  23. #ifdef DEBUG
  24. extern int stderr;
  25. #endif
  26.  
  27. extern    int    __col_pos;
  28.  
  29. int
  30. write(fd, buf, nbytes)
  31. int        fd;
  32. char        *buf;
  33. unsigned int    nbytes;
  34. {
  35.   char    *s;
  36.  
  37.   if (!(__ttymode & CRMOD) || !isatty(fd))
  38.  
  39. #ifdef DEBUG
  40.         {
  41.         int result = Fwrite(fd, nbytes, buf);
  42.  
  43.         fprintf(stderr, "write(%d, %X, %d)->%d\n", 
  44.             fd, buf, nbytes, result);
  45.         return(result);
  46.         }
  47. #else
  48.     return Fwrite(fd, nbytes, buf);
  49. #endif
  50.  
  51.   for (s = buf ; nbytes > 0 ; s++, nbytes-- )
  52.     if (*s == '\n') 
  53.         {
  54. /*        Bconout(2, '\r');
  55.         Bconout(2, '\n');    */
  56.         console_write_byte(2, '\r');
  57.         console_write_byte(2, '\n');
  58.         __col_pos = 0;
  59.         } 
  60.         else
  61.         {
  62.         if (*s == '\r')
  63.             __col_pos = 0;
  64.             else
  65.         if (*s >= ' ' && *s < 0177)
  66.             __col_pos++;
  67.             else
  68.         if (*s == '\t')
  69.             __col_pos = (__col_pos | 7) + 1;
  70. /*        Bconout(2, *s);        */
  71.         console_write_byte(2, *s);
  72.         }
  73.   return nbytes;
  74. }
  75.